package com.example.restatr.Atcivity.JobSearch;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.restatr.Atcivity.Main.MainActivity;
import com.example.restatr.R;
import com.example.restatr.Tools;

import org.json.JSONException;
import org.json.JSONObject;

public class JobInfoAt extends AppCompatActivity {
    private Toolbar tb;
    private TextView barTitle;
    private EditText search;
    private TextView professionName;
    private TextView salary;
    private TextView need;
    private TextView contacts;
    private TextView location;
    private TextView obligation;
    private TextView companyName;
    private TextView introductory;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_job_info_at);

        tb = findViewById(R.id.toolbar);
        barTitle = findViewById(R.id.bar_Title);
        search = findViewById(R.id.search);
        professionName = findViewById(R.id.professionName);
        salary = findViewById(R.id.salary);
        need = findViewById(R.id.need);
        contacts = findViewById(R.id.contacts);
        location = findViewById(R.id.location);
        obligation = findViewById(R.id.obligation);
        companyName = findViewById(R.id.companyName);
        introductory = findViewById(R.id.introductory);
        Tools.SetBarTitle(tb,barTitle,"职位详情",search,this,true);
        tb.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()){
                    case R.id.item1:
                        startActivity(new Intent(JobInfoAt.this,JobResumeAt.class));
                        break;
                }
                return true;
            }
        });
        Intent intent = getIntent();
        professionName.setText(intent.getStringExtra("professionName"));
        salary.setText(intent.getStringExtra("salary"));
        need.setText(intent.getStringExtra("need"));
        contacts.setText(intent.getStringExtra("contacts"));
        location.setText(intent.getStringExtra("location"));
        obligation.setText(intent.getStringExtra("obligation"));
        GetCompanyInfo();


    }

    private void GetCompanyInfo(){
        new Thread(()->{
                String token = Tools.Get("/prod-api/api/job/company/1", MainActivity.sp.getString("token", ""));
                runOnUiThread(()->{
                    try {
                        JSONObject jx = new JSONObject(token);
                        int code = jx.getInt("code");
                        if (code==200){
                            JSONObject data = jx.getJSONObject("data");
                            companyName.setText(data.getString("companyName"));
                            introductory.setText(data.getString("introductory"));
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                });
        }).start();
    }

    public void onClick(View view) {
        JobSearchAt jobSearchAt = new JobSearchAt();
        jobSearchAt.deliverResume(jobSearchAt.getPos(),JobInfoAt.this);
    }

}